package com.yundahh.u8c.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.yundahh.u8c.config.U8CConfig;
import com.yundahh.u8c.dao.base.U8CBaseDao;
import com.yundahh.u8c.entity.base.BaseVO;
import com.yundahh.u8c.entity.base.U8CResult;
import com.yundahh.u8c.entity.bom.BomChild;
import com.yundahh.u8c.entity.bom.BomParent;
import com.yundahh.u8c.entity.puorder.PuOrderChild;
import com.yundahh.u8c.entity.puorder.PuOrderParent;
import com.yundahh.u8c.enums.OperationType;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;

public class BomDao extends U8CBaseDao<BaseVO<BomParent, BomChild>> {



    @Override
    public String getApiUrl() {
        return "/u8cloud/api/uapbd/bdbom";
    }

    public BomDao(U8CConfig config) {
        super(config);
    }

    /**
     * 新增bom
     * @param boms
     * @return
     */
    public U8CResult<BaseVO<BomParent,BomChild>> save(List<BaseVO<BomParent, BomChild>> boms) throws IOException {
        HashMap<String,Object> param=new HashMap<>();
        param.put("vos",boms);
        return send(OperationType.SAVE, param);
    }

    public U8CResult<BaseVO<BomParent,BomChild>> update(List<BaseVO<BomParent, BomChild>> boms) throws IOException {
        HashMap<String,Object> param=new HashMap<>();
        param.put("vos",boms);
        return send(OperationType.UPDATE, param);
    }


    /**
     * 获取某个公司的物料bom
     * @param unicode
     * @param wlbm
     * @return
     * @throws IOException
     */
    public List<BaseVO<BomParent, BomChild>> getBom(String unicode,String wlbm) throws IOException {
        return getBom(unicode, wlbm, null);
    }

    public List<BaseVO<BomParent, BomChild>> getBom(String unicode,String wlbm,String version) throws IOException {
        String url= config.getServerUrl()+getApiUrl();
        HashMap params=new HashMap();
        params.put("pk_corp",unicode);//传参的时候pk_corp其实就是unitcode公司编码，u8c的问题
        params.put("wlbm",wlbm);
        if(StringUtils.isNotBlank(version)){
            params.put("version",version);
        }
        U8CResult<BaseVO<BomParent, BomChild>> result = send(OperationType.QUERY, params);
        return result.getResultData().getDatas();
    }

    public U8CResult<BaseVO<BomParent, BomChild>> getBomList(String unicode,int pageNo,int pageSize) throws IOException {
        HashMap params=new HashMap();
        params.put("pk_corp",unicode);//传参的时候pk_corp其实就是unitcode公司编码，u8c的问题
        params.put("page_now",pageNo);
        params.put("page_size",pageSize);
        U8CResult<BaseVO<BomParent, BomChild>> result = send(OperationType.QUERY, params);
        return result;
    }
}
